# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=SDL2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.4
pkgrel=1
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (Version 2) (mingw-w64)"
arch=('any')
url="https://libsdl.org"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libiconv")
options=('staticlibs' 'strip')
source=("https://libsdl.org/release/SDL2-${pkgver}.tar.gz"
        SDL2-prevent-duplicate-d3d11-declarations.patch
        SDL2-fix-gcc-compatibility.patch)
sha256sums=('da55e540bf6331824153805d58b590a29c39d2d506c6d02fa409aedeab21174b'
            '3b873346ac0c2b159dd81d21fca9d52be71699f5e04d2867049f0db4a2f4edfc'
            '8b33198c272a2906c83e83957caf9f19ddac31422623f9e6caca0fc1e4ba416a')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/SDL2-fix-gcc-compatibility.patch
  patch -p1 -i ${srcdir}/SDL2-prevent-duplicate-d3d11-declarations.patch

  ./autogen.sh
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  sed -e "s|-mwindows||g" -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/sdl2.pc
}
